﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//敌方坦克
public class MonsterTank : TankBase
{
    //3.当目标到达一定范围内过后 间隔一段时间 攻击下一个目标
    //间隔开火时间
    public float fireOffsetTime = 1;
    //发射位置
    public Transform[] shootPos;
    //子弹预设体
    public GameObject bulletObj;
    //间隔时间
    private float nowTime = 0;

    public float NowTime
    {
        get
        {
            return nowTime;
        }
        set
        {
            nowTime = value;
        }
    }

    public override void Fire()
    {
        nowTime = 0;
        for (int i = 0; i < shootPos.Length; i++)
        {
            //实例化子弹
            GameObject obj = Instantiate(bulletObj, shootPos[i].position, shootPos[i].rotation);
            //设置子弹拥有者,方便后面进行属性计算
            Bullet bullet = obj.GetComponent<Bullet>();
            bullet.SetFather(this);
        }
    }

    public virtual bool CheckFire()
    {
        return nowTime > fireOffsetTime;
    }

    void Update()
    {
        GameLoop();
    }

    public virtual void GameLoop()
    {
        NowTime += Time.deltaTime;
        if (CheckFire())
            Fire();
    }
}
